% v55: including enhanced neighbor criteria
function y = minDistSearch(pt,model)

        min_d = inf;
        nbThr = 10;
        
        for i=1:size(model,3),
            
            minx_nb = min(model(1,:,i));
            miny_nb = min(model(2,:,i));
            maxx_nb = max(model(1,:,i));
            maxy_nb = max(model(2,:,i));
            
            if (pt(1,1)>=minx_nb-nbThr)&&(pt(1,1)<=maxx_nb+nbThr)&& ...
                                (pt(2,1)>=miny_nb-nbThr)&&(pt(2,1)<=maxy_nb+nbThr),
            
                dist = DistP2Segment(pt,model(:,:,i));
                if dist < min_d, min_d = dist; end
%             else
%                 min_d = inf;
%                 break;
            end
        end
        
        y = min_d;
end